import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from "typeorm";

import { ExtOwner, ExtUUidTuple, VARCHAR50_PG, BIGINT_PG, User } from "qqlx-core";

import { TransformerBigInteger } from "@lib/orm.transfor.number";
import { TransformerVarchar50 } from "@lib/orm.transfor.string";
import { TransformerBoolean } from "@lib/orm.transfor.boolean";

import { NotFunction } from "@/alpha/ext.base";

export class JustUUidSchema extends NotFunction implements ExtUUidTuple {
  @PrimaryGeneratedColumn("uuid")
  uuid32!: VARCHAR50_PG;

  @Column({ transformer: new TransformerBoolean() })
  isDisabled: boolean = false;

  @Column({ transformer: new TransformerBigInteger() })
  timeCreate: BIGINT_PG = Date.now().toString();

  @Column({ transformer: new TransformerBigInteger() })
  timeUpdate: BIGINT_PG = Date.now().toString();
}

export class OwnerUUidSchema extends JustUUidSchema implements ExtOwner {
  @Column({ transformer: new TransformerVarchar50() })
  refOwnerUUid32!: VARCHAR50_PG;

  // ======= JOIN =======
  // ======= JOIN =======
  // ======= JOIN =======

  @ManyToOne("UserSchema")
  @JoinColumn({ name: "refOwnerUUid32", referencedColumnName: "uuid32" })
  justOwner!: User;
}
